package DVD;

import java.util.Scanner;

public class AdminRentSys {

    Scanner sc = new Scanner(System.in);
    DVD[] dvds = RentDao.dvds;

    public void start() {
        System.out.println("1.查看DVD信息\t2.上架\t3.下架\t4.管理用户信息");
        switch (sc.next()) {
            case "1":
                showDVD();
                break;
            case "2":
                upDVD();
                break;
            case "3":
                downDVD();
                break;
            case "4":
                mangeUser();
                break;
            default:
                System.out.println("输入有误");
                start();
        }
    }

    public void showDVD() {

        System.out.println("DVD名称" + "\tDVD编号" + "DVD租借状态");
        for (int i = 0; i < RentDao.dvdCount; i++) {
            System.out.println(dvds[i].getName() + "\t" + dvds[i].getId() + "\t" + dvds[i].isBorrowStatus());
        }
    }

    public void upDVD() {
        while (true) {
            System.out.println("请选择：1.新增上架\t2.普通上架");

            int choose = sc.nextInt();

            if (1 == choose) {
                DVD[] dvds = RentDao.dvds;
                System.out.println("输入DVD名称");
                String name = sc.next();
                System.out.println("输入DVD编号");
                String id = sc.next();
                System.out.println("输入DVD价格");
                double money = sc.nextDouble();
                dvds[RentDao.dvdCount + 1] = new DVD(name, id, money);
                dvds[RentDao.dvdCount + 1].setBorrowStatus(false);
                dvds[RentDao.dvdCount + 1].setUpDownStatus(true);
            } else if (2 == choose) {
                showDVD();
                DVD[] dvds = RentDao.dvds;
                System.out.println("请输入下架的编号");
                String dvdId = sc.next();
                System.out.println("输入DVD名称");
                String name = sc.next();
                dvds[Integer.parseInt(dvdId)].setName(name);
                System.out.println("输入DVD编号");
                String id = sc.next();
                dvds[Integer.parseInt(dvdId)].setId(id);
                System.out.println("输入DVD价格");
                double money = sc.nextDouble();
                dvds[Integer.parseInt(dvdId)].setMoney(money);
            } else {
                System.out.println("我不理解");
                upDVD();
            }

        }
    }

    public void downDVD() {
        while (true) {

            System.out.println("请输入DVD编号：");
            String id = sc.next();

            for (int i = 0; i < RentDao.dvdCount; i++) {
                if (dvds[i].equals(id)) {
                    dvds[i] = dvds[i + 1];
                }
            }
            RentDao.dvdCount--;
        }
    }

    public void mangeUser() {
        while (true) {
            System.out.println("请输入要管理的用户名：");
            String username = sc.next();
            for (int i = 0; i < RentDao.userCount; i++) {
                if (username.equals(RentDao.people[i].getUsername())) {
                    RentDao.people[i].setStatus(0);
                }
            }
            System.out.println("修改成功");
        }
    }
}